<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('列表')"/>
    <script th:src="@{/static/admin/js/pdf.js}"></script>
    <script th:src="@{/static/admin/js/pdf.worker.js}"></script>
</head>
<style>
    .layui-tab-title {
        /*background-color: #009688;*/
        background-color: #36b368;
        color: #F5F5F5;
        border-bottom: 2px solid #CCCCCC;
    }

    .layui-this {
        background-color: #F5F5F5;
    }

    .layui-tab-item {
        background-color: #F5F5F5;
        border: 1px solid #CCCCCC;
    }

    .layui-table-cell {
        padding: 0 5px;
        height: auto !important;
        overflow: visible;
        text-overflow: inherit;
        white-space: normal;
        word-break: break-all;
        line-height: 26px !important;
    }

    .layui-table th {
        text-align: center !important;
    }

    .layui-form-radio * {
        margin-right: 10px;
        margin-left: 5px;
    }

    .layui-table td {
        font-size: 13px !important;
    }
</style>
<body>
<!--<button class="pear-btn pear-btn-md pear-btn-primary" lay-submit-->
<!--        lay-filter="monthtask-submit">-->
<!--    <i class="layui-icon layui-icon-upload-circle"></i>-->
<!--    提报-->
<!--</button>-->
<div class="layui-tab layui-tab-brief" lay-filter="test-hash">
    <ul class="layui-tab-title" id="layui-tab-title">
    </ul>
    <div class="layui-tab-content" id="layui-tab-content">
    </div>
</div>
<th:block th:include="include :: footer"/>

<!--必备条件表格&#45;&#45;自评价列单选-->
<script type="text/html" id="stateBar">
    <input type="radio" disabled="disabled" name="state{{d.id}}" value="{{d.id+'^^^'+d.typeSelf+'^^^1'}}" title="合格" {{
           d.typeSelf== 1 ? 'checked' : '' }}>&nbsp;
    <input type="radio" disabled="disabled" name="state{{d.id}}" value="{{d.id+'^^^'+d.typeSelf+'^^^0'}}" title="不合格" {{
           d.typeSelf== 0 ? 'checked' : '' }}>&nbsp;
</script>
<!--必备条件表格&#45;&#45;自评价列单选-->
<script type="text/html" id="stateBar1">
    <input type="radio" name="state{{d.id}}sh" value="{{d.id+'^^^'+d.typeReview+'^^^1'}}" title="合格"
           lay-filter="lockDemo"
           {{ d.typeReview== 1 ? 'checked' : '' }}>&nbsp;
    <input type="radio" name="state{{d.id}}sh" value="{{d.id+'^^^'+d.typeReview+'^^^0'}}" title="不合格"
           lay-filter="lockDemo"
           {{ d.typeReview== 0 ? 'checked' : '' }}>&nbsp;
</script>

<script id="taskFillingScore-bar3" type="text/html">
    {{#if(d.type == 3 ){ }}
    <!--    <img th:src="@{/static/admin/images/img/carryOut.png}" class="layui-nav-img">-->
    {{# }else if (d.isAuditedit === '1'){ }}
    <img th:src="@{/static/admin/images/img/carryOut.png}" class="layui-nav-img">
    {{# }else{ }}
    <img th:src="@{/static/admin/images/img/notCarryOut.png}" class="layui-nav-img">
    {{# } }}
</script>
<!--除”必备条件“外，其他表格”评价方式及材料“显示事件-->
<script type="text/html" id="content-event">
    {{#  if(d.type != 3){ }}
    <!--    <button class="pear-btn pear-btn-warming pear-btn-sm"-->
    <!--            lay-event="" title="填报帮助文档" onclick="viewrule('{{d.content}}')"><i class="layui-icon layui-icon-search"></i>-->
    <!--    </button>-->
    <button class="pear-btn pear-btn-warming pear-btn-sm"
            lay-event="" title="评价方式" onclick="viewrule('{{d.content}}')"><i class="layui-icon layui-icon-search"></i>
    </button>
    <button class="pear-btn pear-btn-warming pear-btn-sm"
            lay-event="" title="上传佐证" onclick="uploadCorroboration('{{d.fkParentProjectId}}')"><i
            class="layui-icon layui-icon-upload"></i>
    </button>
    {{#  }else{ }}
    <span>{{d.content}}</span>
    {{#  } }}
</script>

<script th:inline="javascript" type="text/javascript">

    var tabTitleList = [[${tabTitleList}]];
    var taskId = [[${taskId}]];
    var tabTiletHtml = "";
    var tabBodyHtml = ""

    for (var i = 0; i < tabTitleList.length; i++) {
        tabTiletHtml += '<li className="layui-this" lay-id=' + tabTitleList[i].id + '>' + tabTitleList[i].content + '</li>'
        tabBodyHtml += '<div class="layui-tab-item" id="tab' + tabTitleList[i].num + '">' + '<table id="tab' + tabTitleList[i].num + '-table"></table>' + '</div>'
    }

    $('#layui-tab-title').html(tabTiletHtml);
    $('#layui-tab-content').html(tabBodyHtml);

    var MODULE_PATH = rootPath + "/MonthSupplytaskAuditController/";
    var MODULE_PATH_NEC = rootPath + "/MonthNecessaryController/";
    var MODULE_PATH_DTL = rootPath + "/MonthSupplytaskDtlController/";
    var MODULE_PATH_FILE = rootPath + "/InfoFileController/";

    layui.use(['table', 'form', 'jquery', 'element', 'laydate', 'dtree'], function () {
        //设置第一个页签默认展示
        $('#tab' + tabTitleList[0].num).attr('class', "layui-tab-item layui-show");
        $("ul li:first").attr('class', "layui-this");

        var table = layui.table;
        var form = layui.form;

        var cols0 = [
            [
                // {type: 'checkbox'},
                {title: '项目编号', field: 'num', align: 'center', width: 100,},
                {title: '一级项目', field: 'firstProject', align: 'center', width: 150,},
                {title: '二级项目', field: 'secondProject', align: 'center', width: 450,},
                {title: '检查方式', field: 'testMode', align: 'center', width: 450,},
                {title: '责任部门', field: 'resDeptName', align: 'center', width: 100,},
                {title: '自评价', field: 'typeSelf', align: 'center', templet: '#stateBar'},
                {title: '审核更正', field: 'typeReview', align: 'center', templet: '#stateBar1'},
            ]
        ]

        var cols1 = [
            [
                {title: '指标编号', field: 'num', align: 'center', width: 100},
                {
                    title: '指标名称', field: 'name', align: 'center', width: 420, templet: function (d) {
                        if (d.type == 3) {
                            return '<div style="text-align:center">' + d.name + '</div>'
                        } else {
                            return '<div style="text-align:left">' + d.name + '</div>'
                        }
                    }
                },
                {
                    title: '工作要求及完成情况',
                    field: 'selfValue',
                    align: 'center',
                    width: 280,
                    templet: function (d) {
                        if (d.type === '3') {
                            return '<span >' + d.selfValue + '</span>';
                        } else {
                            if (d.tactics === '1' || d.tactics === '3') {
                                var selfValue = d.selfValue == null ? "" : d.selfValue
                                if (d.isauto === 1) {
                                    return '<div class="layui-input-block" style="text-align:left">' +
                                        '<input type="text" style="width: 100px;text-align:center" disabled="disabled" id = "' + d.id + '" value="' + selfValue + '"  data-old = "' + d.selfValue + '" data-num = "' + d.num + '" data-unit = "' + d.measuringUnit + '">' + '<span>' + d.measuringUnit + '</span>'
                                } else {
                                    return '<div class="layui-input-block" style="text-align:left">' +
                                        '<input type="text" style="width: 100px;text-align:center" disabled="disabled" id = "' + d.id + '" value="' + selfValue + '" onblur="onblurOn(this)" data-old = "' + d.selfValue + '" data-num = "' + d.num + '" data-unit = "' + d.measuringUnit + '">' + '<span>' + d.measuringUnit + '</span>'
                                }
                            } else if (d.tactics === '2') {
                                if (d.isauto === 1) {
                                    if (d.selfValue === "1") {
                                        return '<div class="layui-form layui-input-block" style="text-align:left;">' +
                                            '<input type="radio" disabled="disabled" checked name="radio' + d.id + '" value="' + d.id + '^^^' + d.selfValue + '^^^1^^^' + d.num + '"  title="是" lay-filter="selfValueDemo">' +
                                            '<input type="radio" disabled="disabled" name="radio' + d.id + '" value="' + d.id + '^^^' + d.selfValue + '^^^0^^^' + d.num + '" title="否" lay-filter="selfValueDemo">';
                                    } else {
                                        return '<div class="layui-form layui-input-block" style="text-align:left;">' +
                                            '<input type="radio" disabled="disabled" name="radio' + d.id + '" value="' + d.id + '^^^' + d.selfValue + '^^^1^^^' + d.num + '" title="是" lay-filter="selfValueDemo">' +
                                            '<input type="radio" disabled="disabled" checked name="radio' + d.id + '" value="' + d.id + '^^^' + d.selfValue + '^^^0^^^' + d.num + '" title="否" lay-filter="selfValueDemo">';
                                    }
                                } else {
                                    if (d.selfValue === "1") {
                                        return '<div class="layui-form layui-input-block" style="text-align:left;">' +
                                            '<input type="radio" disabled="disabled" name="radio' + d.id + '" value="' + d.id + '^^^' + d.selfValue + '^^^1^^^' + d.num + '" title="是" lay-filter="selfValueDemo" checked>' +
                                            '<input type="radio" disabled="disabled" name="radio' + d.id + '" value="' + d.id + '^^^' + d.selfValue + '^^^0^^^' + d.num + '" title="否" lay-filter="selfValueDemo">';
                                    } else if (d.selfValue === "0") {
                                        return '<div class="layui-form layui-input-block" style="text-align:left;">' +
                                            '<input type="radio" disabled="disabled" name="radio' + d.id + '" value="' + d.id + '^^^' + d.selfValue + '^^^1^^^' + d.num + '" title="是" lay-filter="selfValueDemo" >' +
                                            '<input type="radio" disabled="disabled" name="radio' + d.id + '" value="' + d.id + '^^^' + d.selfValue + '^^^0^^^' + d.num + '" title="否" lay-filter="selfValueDemo" checked>';
                                    } else {
                                        return '<div class="layui-form layui-input-block" style="text-align:left;">' +
                                            '<input type="radio" disabled="disabled" name="radio' + d.id + '" value="' + d.id + '^^^' + d.selfValue + '^^^1^^^' + d.num + '" title="是" lay-filter="selfValueDemo" >' +
                                            '<input type="radio" disabled="disabled" name="radio' + d.id + '" value="' + d.id + '^^^' + d.selfValue + '^^^0^^^' + d.num + '" title="否" lay-filter="selfValueDemo">';
                                    }
                                }
                            } else {
                                return '';
                            }
                        }
                    }
                },
                {
                    title: '审核更正结果',
                    field: 'reviewValue',
                    align: 'center',
                    width: 280,
                    templet: function (d) {
                        if (d.tactics === '1' || d.tactics === '3') {
                            var reviewValue = d.reviewValue == null ? "" : d.reviewValue
                            if (d.isauto === 1) {
                                return '<div class="layui-input-block" style="text-align:left">' +
                                    '<input type="text" style="width: 100px;text-align:center" disabled="disabled" id = "' + d.id + '" value="' + reviewValue + '"  data-old = "' + d.reviewValue + '" data-num = "' + d.num + '" data-unit = "' + d.measuringUnit + '">' + '<span>' + d.measuringUnit + '</span>'
                            } else {
                                return '<div class="layui-input-block" style="text-align:left">' +
                                    '<input type="text" style="width: 100px;text-align:center" id = "' + d.id + 'sh" value="' + reviewValue + '" onmouseout="onblurAudit(this)" data-old = "' + d.reviewValue + '" data-num = "' + d.num + '" data-unit = "' + d.measuringUnit + '">' + '<span>' + d.measuringUnit + '</span>'
                            }
                        } else if (d.tactics === '2') {
                            if (d.isauto === 1) {
                                if (d.selfValue === "1") {
                                    return '<div class="layui-form layui-input-block" style="text-align:left;">' +
                                        '<input type="radio" disabled="disabled" checked name="radio1' + d.id + '" value="' + d.id + '^^^' + d.reviewValue + '^^^1^^^' + d.num + '"  title="是" lay-filter="reviewValueDemo">' +
                                        '<input type="radio" disabled="disabled" name="radio1' + d.id + '" value="' + d.id + '^^^' + d.reviewValue + '^^^0^^^' + d.num + '" title="否" lay-filter="reviewValueDemo">';
                                } else {
                                    return '<div class="layui-form layui-input-block" style="text-align:left;">' +
                                        '<input type="radio" disabled="disabled" name="radio1' + d.id + '" value="' + d.id + '^^^' + d.reviewValue + '^^^1^^^' + d.num + '" title="是" lay-filter="reviewValueDemo">' +
                                        '<input type="radio" disabled="disabled" checked name="radio1' + d.id + '" value="' + d.id + '^^^' + d.reviewValue + '^^^0^^^' + d.num + '" title="否" lay-filter="reviewValueDemo">';
                                }
                            } else {
                                if (d.reviewValue === "1") {
                                    return '<div class="layui-form layui-input-block" style="text-align:left;">' +
                                        '<input type="radio" name="radio1' + d.id + '" value="' + d.id + '^^^' + d.reviewValue + '^^^1^^^' + d.num + '" title="是" lay-filter="reviewValueDemo" checked>' +
                                        '<input type="radio" name="radio1' + d.id + '" value="' + d.id + '^^^' + d.reviewValue + '^^^0^^^' + d.num + '" title="否" lay-filter="reviewValueDemo">';
                                } else if (d.reviewValue === "0") {
                                    return '<div class="layui-form layui-input-block" style="text-align:left;">' +
                                        '<input type="radio" name="radio1' + d.id + '" value="' + d.id + '^^^' + d.reviewValue + '^^^1^^^' + d.num + '" title="是" lay-filter="reviewValueDemo" >' +
                                        '<input type="radio" name="radio1' + d.id + '" value="' + d.id + '^^^' + d.reviewValue + '^^^0^^^' + d.num + '" title="否" lay-filter="reviewValueDemo" checked>';
                                } else {
                                    return '<div class="layui-form layui-input-block" style="text-align:left;">' +
                                        '<input type="radio" name="radio1' + d.id + '" value="' + d.id + '^^^' + d.reviewValue + '^^^1^^^' + d.num + '" title="是" lay-filter="reviewValueDemo" >' +
                                        '<input type="radio" name="radio1' + d.id + '" value="' + d.id + '^^^' + d.reviewValue + '^^^0^^^' + d.num + '" title="否" lay-filter="reviewValueDemo">';
                                }
                            }
                        } else {
                            return '';
                        }
                    }

                },
                {
                    title: '评价周期', field: 'evaluationPeriod', align: 'center', templet: function (d) {
                        if (d.evaluationPeriod === '0') {
                            return '月度';
                        } else if (d.evaluationPeriod === '1') {
                            return '季度';
                        } else if (d.evaluationPeriod === '2') {
                            return '半年';
                        } else if (d.evaluationPeriod === '3') {
                            return '年初';
                        } else if (d.evaluationPeriod === '4') {
                            return '年末';
                        } else {
                            return '';
                        }
                    }
                },

                // {
                //     title: '是否审核更正', field: 'isAuditedit', align: 'center', templet: function (d) {
                //         if (d.isAuditedit === '0') {
                //             return '未更改';
                //         } else if (d.isAuditedit === '1') {
                //             return '审核更改';
                //         } else {
                //             return ''
                //         }
                //     }
                // },
                {title: '是否审核更正', toolbar: '#taskFillingScore-bar3', align: 'center', width: 100},
                // {
                //     title: '任务状态', field: 'taskState', align: 'center', templet: function (d) {
                //         if (d.taskState === '0') {
                //             return '未填报';
                //         } else if (d.taskState === '1') {
                //             return '审核中';
                //         } else if (d.taskState === '2') {
                //             return '驳回重新自评中';
                //         } else {
                //             return '';
                //         }
                //     }
                // },
                {
                    title: '评价方式及材料',
                    field: 'content',
                    align: 'center',
                    templet: '#content-event',
                    width: 160,
                    merge: true
                },
                {title: '项目分值', field: 'score', align: 'center', merge: true},
                {title: '自评分', field: 'proscore', align: 'center', merge: true},
                {title: '审核分', field: 'auditScore', align: 'center', merge: true},
                // {title: '操作', toolbar: '#infoProject-bar', align: 'center'}
            ]
        ]

        //table表单列表
        table.render({
            elem: '#tab0-table',
            url: MODULE_PATH_NEC + 'listbyDep/' + [[${taskId}]],
            page: false,
            method: 'get',
            cols: cols0,
            skin: 'line',
            id: 'tab0-table',
            done: function (res) {
                res.data.forEach(function (item, index) {
                    if (item.type == 3) {
                        var tr = $(".layui-table").find("tbody tr[data-index='" + index + "']");
                        tr.css("background-color", "rgb( 0 , 176 , 80 )");
                        tr.find(".layui-table-cell").css("color", "#ffffff");
                    }
                });
            }
        });

        var table_data = new Array();
        for (var j = 0; j < tabTitleList.length; j++) {
            if (tabTitleList[j].num != '0') {
                //table表单列表
                table.render({
                    elem: '#tab' + tabTitleList[j].num + '-table',
                    url: MODULE_PATH_DTL + 'list4audit/' + [[${taskId}]] + '/' + tabTitleList[j].num,
                    page: false,
                    method: 'get',
                    cols: cols1,
                    skin: 'line',
                    id: 'tab' + tabTitleList[j].num + '-table',
                    scrollPos: 'fixed',
                    loading: false,
                    done: function (res) {
                        var that = this.elem.next();
                        table_data = res.data;
                        console.log(table_data)
                        for (var i = 0; i < res.data.length; i++) {
                            if (res.data[i].type == 3) {
                                var index = res.data[i]['LAY_TABLE_INDEX'];
                                var tr = that.find(".layui-table tr[data-index='" + index + "']");
                                // tr.css("cssText", "height:100px !important");
                                tr.css("background", "rgba(192,252,179,0.35)");
                                tr.find("a[lay-event='put']").prop('disabled', true);
                                tr.find("a[lay-event='put']").removeClass("layui-btn-normal").addClass("layui-btn-disabled");
                            }
                            if (res.data[i].isAuditedit == '1') {
                                var index = res.data[i]['LAY_TABLE_INDEX'];
                                that.find(".layui-table tr[data-index='" + index + "'] td[data-field='isAuditedit']").css("background-color", "#FF9F1E");
                            }
                        }
                        merge(this);
                    }
                });
            }
        }

        form.on('radio(lockDemo)', function (data) {
            // //id
            // console.log(data.value.split('^^^')[0])
            // //是否--回显
            // console.log(data.value.split('^^^')[1])
            // //是否---前端值
            // console.log(data.value.split('^^^')[2])

            var id = data.value.split('^^^')[0];
            var typeReviewValue = data.value.split('^^^')[2];
            console.log(id);
            console.log(typeReviewValue);
            $.ajax({
                url: MODULE_PATH_NEC + '/updateAudit',
                data: JSON.stringify({"id": id, "typeReview": typeReviewValue}),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function (result) {
                    if (result.code == 200) {
                        layui.table.reload("tab0-table");
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                        layui.table.reload("tab0-table");
                    }
                }
            })
        })
        //查看佐证 -d为id
        window.uploadCorroboration = function (d) {
            var index = layer.open({
                type: 2,
                title: '查看佐证',
                shade: 0.1,
                area: ['1300px', '650px'],
                maxmin: true,
                content: MODULE_PATH_FILE + 'fileview/' + d + '/3/' + taskId
            });
            // layer.full(index)
        }

        //查看评分细则
        window.viewrule = function (d) {
            layer.open({
                type: 1,
                title: '评价方式',
                area: ['500px', '500px'],
                // content: '<div><textarea name="description">'+d+'</textarea></div>'
                content: d
            });
        }

        //除必备条件其他所有表格--单选监听事件
        form.on('radio(reviewValueDemo)', function (data) {
            console.log(data)
            //id
            console.log(data.value.split('^^^')[0])
            //是否--回显
            console.log(data.value.split('^^^')[1])
            //是否---前端值
            console.log(data.value.split('^^^')[2])


            var id = data.value.split('^^^')[0];
            var reviewValue = data.value.split('^^^')[2];
            var num = data.value.split('^^^')[3];
            var tab = num.split(".")[0]
            console.log(id)
            $.ajax({
                url: MODULE_PATH + '/updateAudit',
                data: JSON.stringify({"id": id, "reviewValue": reviewValue}),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function (result) {
                    if (result.code == 200) {
                        var tabletab = 'tab' + tab + '-table'
                        layui.table.reloadData(tabletab, {
                            scrollPos: 'fixed',
                            loading: false,
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                        var tabletab = 'tab' + tab + '-table'
                        layui.table.reloadData(tabletab, {
                            scrollPos: 'fixed',
                            loading: false,
                        });
                    }
                }
            })
        })

        //审核值input监听事件
        window.onblurAudit = function (e) {
            //新输入的内容
            console.log("新输入的内容---" + e.value)
            //id
            console.log("id-----" + e.id)
            //旧的内容
            console.log("旧的内容-----" + $('#' + e.id).attr('data-old'))
            var id = e.id;
            var reviewValue = e.value;
            var num = $('#' + e.id).attr('data-num')
            var tab = num.split(".")[0]
            var old = $('#' + e.id).attr('data-old')
            var unit = $('#' + e.id).attr('data-unit')
            var tabletab = 'tab' + tab + '-table'
            var updateflag = true;

            //数据规范
            //百分数0~100待优化

            if (reviewValue === old) {
                console.log("值相同，不刷新")
                updateflag = false
            }

            if (reviewValue == null || reviewValue === "" || reviewValue.length === 0) {
                if (!(old == null || old === "")) {
                    updateflag = true
                } else {
                    updateflag = false
                }
            } else {
                var reg = /^[0-9]+(\.[0-9]{0,2})?$/;
                var reg1 = /^\d+$/;
                if (reg.test(reviewValue)) { //正则匹配通过
                    if (unit === "%") {
                        if (!(reviewValue >= 0 && reviewValue <= 100)) {
                            layer.msg("指标编号为" + num + "的数据行百分数填写不规范", {icon: 2, time: 2000});
                            layui.table.reloadData(tabletab, {
                                scrollPos: 'fixed',
                                loading: false,
                            });
                            updateflag = false;
                        }
                    } else {
                        if (!reg1.test(reviewValue)) {
                            layer.msg("指标编号为" + num + "的数据行数据填写不规范，请填写正整数或0", {icon: 2, time: 2000});
                            layui.table.reloadData(tabletab, {
                                scrollPos: 'fixed',
                                loading: false,
                            });
                            updateflag = false;
                        }
                    }
                } else {
                    updateflag = false;
                    layer.msg("指标编号为" + num + "的数据行数据填写不规范", {icon: 2, time: 2000});
                    layui.table.reloadData(tabletab, {
                        scrollPos: 'fixed',
                        loading: false,
                    });
                }
            }

            if (updateflag) {
                // $('#' + e.id).css({"color":"red"})
                var recordId = id.substr(0, id.lastIndexOf('sh'))
                $.ajax({
                    url: MODULE_PATH + '/updateAudit',
                    data: JSON.stringify({"id": recordId, "reviewValue": reviewValue}),
                    dataType: 'json',
                    contentType: 'application/json',
                    type: 'post',
                    success: function (result) {
                        if (result.code == 200) {
                            console.log("tabletab返回成功-----" + tabletab)
                            layui.table.reloadData(tabletab, {
                                scrollPos: 'fixed',
                                loading: false,
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                            layui.table.reloadData(tabletab, {
                                scrollPos: 'fixed',
                                loading: false,
                            });
                        }
                    }
                })
            }
        }

        //提报按钮绑定
        form.on('submit(monthtask-submit)', function (data) {
            layer.confirm('审核结果提交后不可修改，是否确认提交？', {
                title: "提交确认",
                icon: 0,
                btn: ['确认', '取消'] //可以无限个按钮
            }, function (data) {
                $.ajax({
                    url: MODULE_PATH + '/auditCommit',
                    data: JSON.stringify({"id": taskId}),
                    dataType: 'json',
                    contentType: 'application/json',
                    type: 'post',
                    success: function (result) {
                        if (result.code == 200) {
                            layer.msg("审核提报完成", {icon: 1, time: 3000}, function () {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.location.reload(); //刷新父页面
                                //parent.layer.close(index);
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 3000});
                        }
                    }
                })
            }, function (data) {
                location.reload();
            });
        });
    })


    function merge(myTable, skipFlag = true) {
        var tableBox = $(myTable.elem).next().children('.layui-table-box'),
            $main = $(tableBox.children('.layui-table-body').children('table').children('tbody').children('tr').toArray().reverse()),
            $fixLeft = $(tableBox.children('.layui-table-fixed-l').children('.layui-table-body').children('table').children('tbody').children('tr').toArray().reverse()),
            $fixRight = $(tableBox.children('.layui-table-fixed-r').children('.layui-table-body').children('table').children('tbody').children('tr').toArray().reverse()),
            cols = myTable.cols[0], mergeRecord = {};

        for (let i = 0; i < cols.length; i++) {
            var item3 = cols[i], field = item3.field;
            if (item3.merge) {
                var mergeField = [field];
                if (item3.merge !== true) {
                    if (typeof item3.merge == 'string') {
                        mergeField = [item3.merge]
                    } else {
                        mergeField = item3.merge
                    }
                }
                mergeRecord[i] = {mergeField: mergeField, rowspan: 1}
            }
        }

        $main.each(function (i) {
            for (var _recordIndex in mergeRecord) {
                var _mergeRecord = mergeRecord[_recordIndex];
                //检查前一个字段
                var _beforeMergeRecord = mergeRecord[_recordIndex - 1];
                //
                if (i === $main.length - 1 || (skipFlag && _beforeMergeRecord && _beforeMergeRecord.rowspan === 1) || isMaster(i, _mergeRecord)) {
                    $(this).children('[data-key$="-' + _recordIndex + '"]').attr('rowspan', _mergeRecord.rowspan);
                    $fixLeft.eq(i).children('[data-key$="-' + _recordIndex + '"]').attr('rowspan', _mergeRecord.rowspan);
                    $fixRight.eq(i).children('[data-key$="-' + _recordIndex + '"]').attr('rowspan', _mergeRecord.rowspan);
                    _mergeRecord.rowspan = 1;
                } else {
                    $(this).children('[data-key$="-' + _recordIndex + '"]').remove();
                    $fixLeft.eq(i).children('[data-key$="-' + _recordIndex + '"]').remove();
                    $fixRight.eq(i).children('[data-key$="-' + _recordIndex + '"]').remove();
                    _mergeRecord.rowspan += 1;
                }
            }
        })

        function isMaster(index, _mergeRecord) {
            var mergeField = _mergeRecord.mergeField;
            var dataLength = layui.table.cache[myTable.id].length;
            for (var i = 0; i < mergeField.length; i++) {

                if (layui.table.cache[myTable.id][dataLength - 2 - index][mergeField[i]]
                    !== layui.table.cache[myTable.id][dataLength - 1 - index][mergeField[i]]) {
                    return true;
                }
            }
            return false;
        }
    }


</script>
</body>
</html>